package org.jeecg.modules.tt_question_collect.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.tt_question_collect.entity.TtCollectFlowNode;
import org.jeecg.modules.tt_question_collect.vo.SysAuditUserVO;

import java.util.List;
import java.util.Map;

/**
 * @Description: 审批流程节点表
 * @Author: jeecg-boot
 * @Date: 2021-02-02
 * @Version: V1.0
 */
public interface TtCollectFlowNodeMapper extends BaseMapper<TtCollectFlowNode>
{

	List<TtCollectFlowNode> queryAuditNodeListByFlowCode(String flowCode);

	@Select("select id as userId, realname as userName from sys_user where user_identity = '2' and id in (select user_id from sys_user_role where role_id = (select id from sys_role where id = #{auditid}))")
	List<SysAuditUserVO> queryAuditUsersByRoleId(@Param("auditid") String auditid);

	@Select("select id as userId, realname as userName from sys_user where user_identity = '2' and id in ${sqlUserId}")
	List<SysAuditUserVO> queryAuditUsersByUserIds(@Param("sqlUserId") String sqlUserId);


	@Select("select * from tt_collect_flow_node where flowcode = '${flowcode}'")
	List<Map<String,Object>> queryCollectNodesList(@Param("flowcode") String flowcode);

	@Select("select max(sortid) from tt_audit_record where scbj = '0'and lclx= '${lclx}' group by tableid having tableid = '${tableid}'")
	int maxSortidBywtid(@Param("tableid") String tableid,@Param("lclx") String lclx);

	@Select("select max(sortid) from tt_collect_flow_node  group by flowcode having flowcode = '${flowcode}'")
	Integer maxSortidByflowcode(@Param("flowcode") String flowcode);


	@Select("select id,realname from sys_user  where phone in ${idname}")
	List<Map<String, Object>> idS(@Param("idname") String idname);

	@Select("select id,realname from sys_user where id in ${idname}")
	List<Map<String, Object>> idD(@Param("idname") String idname);

	@Select("select id,role_name as realname from sys_role where id in ${idname}")
	List<Map<String, Object>> idR(@Param("idname") String idname);

	void addSyjsortid(@Param("sortid")String sortid,@Param("flowcode")String flowcode);

	void addASyjsortid(@Param("sortid")String sortid,@Param("flowcode")String flowcode);

	void delSyjsortid(@Param("sortid")String sortid,@Param("flowcode")String flowcode);

	@Select("select count(0) from tt_collect_flow_node where flowcode = ${flowcode}")
	int isone(@Param("flowcode") String flowcode);

	@Select("select count(0) from tt_collect_flow_node where flowcode = '${flowcode}' and sortid = ${sortid}")
	int Countone(@Param("flowcode") String flowcode,@Param("sortid") String sortid);

	void delmodel(@Param("flowcode") String flowcode,@Param("id") String id);

	@Update("update tt_collect_flow_node set auditid = '${auditid}', auditname = '${username}' where id = '${id}'")
	void updateInfo(@Param("id") String id, @Param("auditid") String auditid, @Param("username") String username);

	@Select("select count(0) from tt_audit_record where tableid = '${id}' and scbj = '0' and lclx = '${lclx}'")
	int queryCount(@Param("id") String id,@Param("lclx") String lclx);

	@Update("update tt_audit_record set scbj = '2' where tableid = '${id}' and scbj = '0' and lclx = '${lclx}'")
	void updatescbj(@Param("id") String id,@Param("lclx") String lclx);

	@Select("select flowname from tt_collect_flow where flowcode ='${flowCode}'")
	String querylcnamebyflowcode(String flowCode);

	@Select("select flowcode from tt_collect_flow where flowtype ='fasplc'")
	String getfacode();

	@Select("select id, nodename,sortid,auditrange,audituserid,auditusername from tt_audit_record t where tableid =  '${tableid}' and sortid = '${sortid}' and scbj = '0'  ")
	List<Map<String,Object>> queryspusersftcuser( String tableid,String sortid);


	@Select("select max(sortid) as maxsortid from tt_audit_record where tableid =  '${id}' and lclx= 'wtlx' and scbj ='0'")
	int getmaxsortid(String id);

	@Select("select  max(isnew) isnew from tt_audit_record where tableid =  '${id}' and sortid =  '${j}' and lclx= 'wtlx' and scbj ='0'")
	String getisnewzt(String id, String j);

	@Select("select user_id from sys_user_role  where role_id =  (select id from sys_role where role_code = 'FANGANQUEREN')")
    List<Map<String,Object>> queryfauserid();
}
